<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
		"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
	<title>dijit.Tree Automatic Tests</title>

	<style type="text/css">
		@import "../../dojo/resources/dojo.css";
		@import "../../dojo/resources/dnd.css";
		@import "../../dojo/tests/dnd/dndDefault.css";
		@import "css/dijitTests.css";
	</style>

	<!-- required: a default dijit theme: -->
	<link id="themeStyles" rel="stylesheet" href="../../dijit/themes/claro/claro.css">
	
	<!-- required: dojo.js -->
	<script type="text/javascript" src="../../dojo/dojo.js"
		djConfig="parseOnLoad: true, isDebug: true"></script>
	
	<!-- not needed, for testing alternate themes -->
	<script type="text/javascript" src="_testCommon.js"></script>

	<script type="text/javascript" src="helpers.js"></script>

	<script language="JavaScript" type="text/javascript">
		dojo.require("doh.runner");
		dojo.require("dijit.dijit"); // optimize: load dijit layer
		dojo.require("dojox.data.JsonRestStore");
		dojo.require("dijit.Tree");
		dojo.require("dijit.tree.ForestStoreModel");
		dojo.require("dijit.tree.dndSource");

		dojo.addOnLoad(function(){
			doh.register("Tree tests",
				[
					function create(){
						var d = new doh.Deferred;
			 			myStore = new dojox.data.JsonRestStore({target:"tree/", labelAttribute:"name"});

			 			doh.t(myStore, "store created");

						myModel = new dijit.tree.ForestStoreModel({
							store: myStore,
							deferItemLoadingUntilExpand: true,
							query: "treeTestRoot",
							childrenAttrs: ["children"]
						});
						doh.t(myModel, "model created");

						myTree = new dijit.Tree({
							id: "myTree",
							model: myModel,
							"label": "Example",
							persist: false,		// persist==true is too hard to test
							dndController: "dijit.tree.dndSource" 
						});
						doh.t(myTree, "tree created");

						dojo.byId("container").appendChild(myTree.domNode);
						myTree.startup();

						setTimeout(d.getTestCallback(function(){
							// Give the tree time to load, and the do checks that it
							// loaded correctly
							doh.t(myTree.rootNode, "root node exists");
							doh.t(myTree.rootNode.isExpanded, "root node is expanded");

							var children = myTree.rootNode.getChildren();
							doh.is(5, children.length, "six children");
							doh.is("node1", children[0].label, "first child");
							doh.f(children[0].isExpanded, "first child not expanded");
						}), 500);
						return d;
					},

					{
						runTest: function openANode(){
							var d = new doh.Deferred;
							
							var first = myTree.rootNode.getChildren()[0];
							
							myTree._onExpandoClick({
								node: first
							});
							setTimeout(function(){
								var firstFirst = first.getChildren()[0];
								myTree._onExpandoClick({
									node: firstFirst
								});
								
								setTimeout(d.getTestCallback(function(){
									// Give the tree time to load the children, and the do checks that it
									// loaded correctly
									
									var children = firstFirst.getChildren();
									doh.is(2, children.length, "two children");
									doh.is("node1.1.1", children[0].label, "first child");
								}), 500);
							}, 500);
							return d;
						},
						timeout: 2000
					}
				]
			);

			doh.run();
		});
	</script>

</head>
<body class="claro">

	<h1 class="testTitle">Dijit.Tree automated tests</h1>
	<div id="container"> <!--  tree will go here --></div>
	<div id="container2"> <!--  tree2 will go here --></div>
</body>
</html>
